/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//$("#LoginButton").click(function(){
 //   login();
//});
//$("#createAccountButton").click(function(){
 //   verifyCA();
//})
function clearRed(){
    $(".accountInputs").css("background-color","#FFFFFF");
}
function verifyCA(){
    var b = 1;
    clearRed();
    if($("#userName").val().trim() == ""){
        //Error
        b = 0;
        $("#userName").css("background-color","#FF3636");
    }
    
    
    //EMAIL VERIFICATION
    if($("#userEmail").val().trim() == ""){
        //Error
        b = 0;
        $("#userEmail").css("background-color","#FF3636");
    }
    else if(!$("#userEmail").val().indexOf(".") == -1){
        b = 0;
        $("#userEmail").css("background-color","#FF3636");
    }
    else if($("#userEmail").val().indexOf("@") == 0){
        b = 0;
        $("#userEmail").css("background-color","#FF3636");
    }
    else if(!$("#userEmail").val().indexOf("@") == $("#userEmail").val().lastIndexOf("@")){ //Only 1 @
        b = 0;
        $("#userEmail").css("background-color","#FF3636");
    }
    else if($("#userEmail").val().indexOf(".") == -1){
        b = 0;
        $("#userEmail").css("background-color","#FF3636");
    }
    else if($("#userEmail").val().lastIndexOf(".") == $("#userEmail").val().length-1 || $("#userEmail").val().lastIndexOf("@") > $("#userEmail").val().lastIndexOf(".")){
        //Is there anything after the final . (usually some webending .com/.net/.tk) || is the final . after the @?
        b = 0;
        $("#userEmail").css("background-color","#FF3636");
    }
    else if($("#userEmail").val().lastIndexOf(".") == $("#userEmail").val().lastIndexOf("@")+1){
        //Is there a char between the @ and the . (i.e is there a associated web domain name
        b = 0;
        $("#userEmail").css("background-color","#FF3636");
    }
    //Password Verification
    
    if($("#userOldPassword").val().trim() == "")
    {
            b = 0;
            $("#userOldPassword").css("background-color","#FF3636");
    }
    if($("#userOldPassword").val().trim() != ($("#password").val().trim()))
    {
         b = 0;
         $("#userOldPassword").css("background-color","#FF3636");
    }   
    
    
    if($("#userNewPassword").val().trim() == ""){
        //Error
        b = 0;
        $("#userNewPassword").css("background-color","#FF3636");
    }
    if($("#userVerifyPassword").val().trim()== ""){
        //Error
        b = 0;
        $("#userVerifyPassword").css("background-color","#FF3636");
    }
    if($("#userNewPassword").val().trim() == "" && $("#userVerifyPassword").val().trim() == ""){
        //Error
        b = 0;
        $("#userNewPassword").css("background-color","#FF3636");
        $("#userVerifyPassword").css("background-color","#F3636");
    }
    else if($("#userNewPassword").val() != $("#userVerifyPassword").val()){
        //Error
        b = 0;
        if($("#userNewPassword").val().trim() == ""){
            $("#userNewPassword").css("background-color","#FF3636");
        }
        $("#userVerifyPassword").css("background-color","#FF3636");
    }
    
    //IS IT VALID?
    if(b == 1){
        $("#editUserForm").submit();//Submit the form!
    }
}


